package com.tencent.wxcloudrun.frontcontroller;

import com.tencent.wxcloudrun.dto.*;
import com.tencent.wxcloudrun.mapper.PingtuanjoinusersMapper;
import com.tencent.wxcloudrun.mapper.PingtuansetMapper;
import com.tencent.wxcloudrun.service.PintuanService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/3/4 19:17
 * @description: TODO
 */
@RestController
@Api(tags = "拼团营销")
public class PintuanController {
    @Autowired
    private PintuanService pintuanService;

    @Autowired
    private PingtuanjoinusersMapper pingtuanjoinusersMapper;

    @Autowired
    private PingtuansetMapper pingtuansetMapper;
    /**
     * 获取拼团设置
     */
    @Operation(summary = "获取拼团设置")
    @PostMapping("/wxcloud/pingtuanSet")
    PingtuanSetResponse pingtuanSet(HttpServletRequest request, @RequestBody PingtuanSetRequest json){
        Integer goodsId = json.getGoodsId();
        Pingtuanset pingtuanset = pingtuansetMapper.selectByGoodsId(goodsId);
        PingtuanSetResponse pingtuanSetResponse = new PingtuanSetResponse();
        pingtuanSetResponse.setCode(0);
        pingtuanSetResponse.setMsg("success");
        pingtuanSetResponse.setData(pingtuanset);
        return pingtuanSetResponse;
    }
    @Operation(summary = "开团接口")
    @PostMapping("/wxcloud/pingtuanOpen")
    PingtuanOpenResponse pingtuanOpen(HttpServletRequest request, @RequestBody PingtuanSetRequest json){
        Integer goodsId = json.getGoodsId();
        int id =  pintuanService.pingtuanOpen(goodsId);
        PingtuanOpenResponse pingtuanOpenResponse = new PingtuanOpenResponse();
        PingtuanOpenData openid = new PingtuanOpenData();
        openid.setId(id);
        pingtuanOpenResponse.setData(openid);
        pingtuanOpenResponse.setCode(0);
        pingtuanOpenResponse.setMsg("success");
        return pingtuanOpenResponse;
    }
    @Operation(summary = "查看某团的所有参与用户")
    @PostMapping("/wxcloud/pingtuanJoinUsers")
    PingtuanJoinUsersResponse pingtuanJoinUsers(HttpServletRequest request, @RequestBody PingtuanJoinUsersRequest json){
        Integer pingtuanId = json.getTuanId();
        List<Pingtuanjoinusers> pingtuanjoinusers = pingtuanjoinusersMapper.selectByTuanId(pingtuanId);
        PingtuanJoinUsersResponse pingtuanJoinUsersResponse = new PingtuanJoinUsersResponse();
        pingtuanJoinUsersResponse.setCode(0);
        pingtuanJoinUsersResponse.setMsg("success");
        pingtuanJoinUsersResponse.setData(pingtuanjoinusers);
        return pingtuanJoinUsersResponse;
    }
    /**
     * 帮人砍一刀
     */
    @Operation(summary = "帮人砍一刀")
    @PostMapping("/wxcloud/kanjiaHelp")
    KanjiaHelpResponse kanjiaHelp(HttpServletRequest request,@RequestBody KanjiaHelpRequest json){
        String joinerUser = json.getJoinerUser();
        String kanjiaId = json.getKjid();


        return null;
    }

    /**
     * 获取满减设置
     */
    @Operation(summary = "获取满减设置")
    @GetMapping("/wxcloud/payBillDiscounts")
    PayBillDiscountsResponse payBillDiscounts(HttpServletRequest request){
        return null;
    }

}
